package com.itheima.goods.controller;
import com.itheima.goods.pojo.Brand;
import com.itheima.goods.service.BrandService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/brand")
@RestController
public class BrandController {
    @Autowired
    private BrandService brandService;
    @GetMapping
    public Result findAllBrand(){
        return brandService.findAllBrand();
    }
    @PostMapping
    public Result addBrand(Brand brand){
       return brandService.addBrand(brand);
    }
    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page,
                           @PathVariable("size") Integer size){
        return brandService.findPage(page,size);
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
    return brandService.findById(id);
    }
    @PutMapping("/{id}")
    public Result updateBrand(@PathVariable("id") Integer id,@PathVariable("brand") Brand brand){
        return brandService.updateBrand(id,brand);
    }
    @DeleteMapping("/{id}")
    public Result deleteBrand(@PathVariable("id") Integer id){
        return brandService.deleteById(id);
    }
}
